/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snake;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author Administrator
 */
public class Main {
    public JButton up = new JButton("up");
    public JButton down = new JButton("down");
    public JButton left = new JButton("left");
    public JButton right = new JButton("right");
    public JButton start = new JButton("start");
    public JButton end = new JButton("pause");

    public void initView() {
        MainCanvas mainCanvas = new MainCanvas(this);


        JFrame frame = new JFrame();
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(mainCanvas, BorderLayout.CENTER);

        JPanel jPanel = new JPanel();
        up = new JButton("↑");
        down = new JButton("↓");
        left = new JButton("←");
        right = new JButton("→");
        start = new JButton("start");
        end = new JButton("pause");

        up.addActionListener(mainCanvas);
        down.addActionListener(mainCanvas);
        left.addActionListener(mainCanvas);
        right.addActionListener(mainCanvas);
        start.addActionListener(mainCanvas);
        end.addActionListener(mainCanvas);

        up.addKeyListener(mainCanvas);
        down.addKeyListener(mainCanvas);
        left.addKeyListener(mainCanvas);
        right.addKeyListener(mainCanvas);
        start.addKeyListener(mainCanvas);
        end.addKeyListener(mainCanvas);


        jPanel.add(start);
        jPanel.add(left);
        jPanel.add(up);
        jPanel.add(down);
        jPanel.add(right);
        jPanel.add(end);
        frame.pack();

        frame.getContentPane().add(jPanel, BorderLayout.SOUTH);

        frame.setResizable(false);
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        Thread thread = new Thread(mainCanvas);
        thread.start();
    }

    /**
     * @param args the command line argumentss
     */
    public static void main(String[] args) {
        new Main().initView();
    }
}
